package com.heiliushu.baseWeb.service.impl.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.heiliushu.baseWeb.Exception.BusinessException;
import com.heiliushu.baseWeb.domain.entity.User;
import com.heiliushu.baseWeb.domain.entity.UserInfo;
import com.heiliushu.baseWeb.domain.mapper.UserMapper;
import com.heiliushu.baseWeb.service.system.RoleService;
import com.heiliushu.baseWeb.service.system.UserService;

@Service
public class UserServiceImpl extends SuperServiceImpl<UserMapper, User>  implements UserService {
	
	@Autowired
	private RoleService roleService;

	@Override
	public UserInfo findByLoginName(String loginName) throws BusinessException {
		User param = new User();
		param.setLoginName(loginName);
		param.setStatus(User.UserStatus.NORMAL.getStatus());
		User user =  this.selectOne(param);
		if(user == null){
			return null;
		}
		UserInfo userInfo = new UserInfo(user);
		userInfo.setRoles(roleService.findRolesByUserId(user.getUserId()));
		return userInfo;
	}

}
